//
//  SAPersonalViewController.m
//  SunOn
//
//  Created by RazeenCheng on 2017/5/2.
//  Copyright © 2017年 NeoZhang. All rights reserved.
//

#import "SAPersonalViewController.h"
#import "SAPersonalHeaderTableViewCell.h"
#import "SAPersonalSectionTableViewCell.h"

#import "SAPersonalInfomationViewController.h" // 个人资料
#import "SAMyCollectionViewController.h" // 我的收藏
#import "SACompanyProfileViewController.h" // 公司简介
#import "SASecurityManagerViewController.h" // 安全管理
#import "SAHelpFeedbackViewController.h" // 帮助与反馈
#import "SAUtilityToolViewController.h" // 实用工具

@interface SAPersonalViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (weak, nonatomic) IBOutlet UITableView *tableView;


@end

@implementation SAPersonalViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    self.tableView.dataSource = self;
    self.tableView.delegate = self;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    self.navigationController.navigationBarHidden = YES;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}




#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 4;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0 || section == 1) {
        return 1;
    } else {
        return 3;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSInteger section = indexPath.section;
    NSInteger row = indexPath.row;
    
    if (section == 0) {
        //
        SAPersonalHeaderTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SAPersonalHeaderTableViewCell" forIndexPath:indexPath];
        __weak typeof (self) weakSelf = self;
        cell.detailBlock = ^(){
            [weakSelf goToPersonalInfomationView];
        };
        return cell;
    } else if (section == 1) {
        SAPersonalSectionTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SAPersonalSectionTableViewCell" forIndexPath:indexPath];
        [cell configCellWithIndexPath:indexPath];
        return cell;
    } else {
        if (row == 0) {
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SeparatorCell" forIndexPath:indexPath];
            return cell;
        } else {
            SAPersonalSectionTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SAPersonalSectionTableViewCell" forIndexPath:indexPath];
            [cell configCellWithIndexPath:indexPath];
            return cell;
        }
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSInteger section = indexPath.section;
    NSInteger row = indexPath.row;
    
    if (section == 0) {
        return 264;
    } else if (section == 1) {
        return 54;
    } else {
        if (row == 0) {
            return 10;
        } else {
            return 54;
        }
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSInteger section = indexPath.section;
    NSInteger row = indexPath.row;

    if (section == 1) {
        // 我的收藏
        SAMyCollectionViewController *myCollectionVC = [self.storyboard instantiateViewControllerWithIdentifier:@"SAMyCollectionViewController"];
        [self.navigationController pushViewController:myCollectionVC animated:YES];
    } else if (section == 2) {
        if (row == 1) {
            // 公司简介
            SACompanyProfileViewController *companyProfileVC = [self.storyboard instantiateViewControllerWithIdentifier:@"SACompanyProfileViewController"];
            [self.navigationController pushViewController:companyProfileVC animated:YES];
        } else if (row == 2) {
            // 安全管理
            SASecurityManagerViewController *securityManagerVC = [self.storyboard instantiateViewControllerWithIdentifier:@"SASecurityManagerViewController"];
            [self.navigationController pushViewController:securityManagerVC animated:YES];
        }
    } else if (section == 3) {
        if (row == 1) {
            // 帮助反馈
            SAHelpFeedbackViewController *helpFeedbackVC = [self.storyboard instantiateViewControllerWithIdentifier:@"SAHelpFeedbackViewController"];
            [self.navigationController pushViewController:helpFeedbackVC animated:YES];
        } else if (row == 2) {
            // 实用工具
            SAUtilityToolViewController *utilityToolVC = [self.storyboard instantiateViewControllerWithIdentifier:@"SAUtilityToolViewController"];
            [self.navigationController pushViewController:utilityToolVC animated:YES];
        }
    }
}


- (void)goToPersonalInfomationView
{
    SAPersonalInfomationViewController *personalInfomationVC = [self.storyboard instantiateViewControllerWithIdentifier:@"SAPersonalInfomationViewController"];
    [self.navigationController pushViewController:personalInfomationVC animated:YES];
}

@end
